/*
    @name: json-sever配置文件
    @description: 更改json-server默认post请求，如果是post请求，代理到get请求，只展示数据，不做更改
    @require: none
    @author: xiaozong Liu(liuxiaozong@odc.cmbchina.cn)
*/

var jsonServer = require('json-server');
var jsonData = require("./cras")
var server = jsonServer.create();
var router = jsonServer.router(jsonData);
var middlewares = jsonServer.defaults();


server.use(middlewares)

server.use(jsonServer.bodyParser)
server.use(function(req, res, next) {
    if (req.method === 'POST') {
        // Converts POST to GET and move payload to query params
        // This way it will make JSON Server that it's GET request
        req.method = 'GET'
        req.query = req.body
    }
    // Continue to JSON Server router
    next()
})

// If you need to scope this behaviour to a particular route, use this
server.post('/comments', function(req, res, next) {
    req.method = 'GET'
    req.query = req.body
    next()
})

server.use("/cras", router);
server.listen(8899, function() {
    console.log('JSON Server is running,listening port 8899')
})